<template>
    <div class="coupon_detail">
        <div class="coupon_info">
            <div class="left">
                <div class="left_top">
                    <div><span>{{ coupon.rate*100}}</span>折</div>
                    <div class="top_info">
                        <div>优惠券</div>
                        <div>{{ coupon.title}}</div>

                    </div>
                </div>
                <div class="left_tips">订单满<span>100</span>减<span>{{100 - coupon.rate*100 }}</span>元</div>
            </div>
            <div class="receive">
                <van-button v-if="list.status==1" type="success" disabled>未使用</van-button>
                <van-button v-else-if="coupon.status==0" type="danger" disabled>已过期</van-button>
                <van-button v-else type="primary" disabled>已使用</van-button>
                
            </div>
        </div>
        <div class="coupon_prompt">
            <div class="prompt_title">温馨提示：</div>
            <div><span>•</span>每人限领1张</div>
            <div><span>•</span>仅限量{{coupon.total}}张，赶快领取！</div>
            <div><span>•</span>领取后{{coupon.createtime_text}}至{{coupon.endtime_text}}有效</div>
        </div>
    </div>

    <Tabbar />
</template>

<script setup>

    const {proxy} = getCurrentInstance();//页面的this
    //获取id
    let id = proxy.$route.query.id;
    let busid = proxy.$business.value.id;
    let list = ref([]);
    let coupon = ref([]);

    onMounted(()=>{
        Info()
    })

    const Info = async ()=>{
        //发起请求
        if(!busid){
            proxy.$fail('请先登录!');
            return false;
        }
        var result = await proxy.$POST({
            url:'/business/couponInfo',
            params:{id:id}
        })
        if(!result) return false
        if(result.code == 0){
            //提醒到底了
            proxy.$fail({
                message:result.msg,
                duration:1000,
                onClose:()=>proxy.$router.go(-1)
            });
            return false
        }
       
        list.value = result.data
        coupon.value =list.value.coupon
        // list.value = Object.values(list.value)
        console.log(list.value.status)
    }
    //前往使用
    // const add = async()=>{

    // }
</script>

<style scoped>
  @import url('/assets/css/CouponInfo.css');
</style>